package models

import (
	"time"
)

// Article 文章表模型
type Article struct {
	ID        uint      `gorm:"type:int;primaryKey;autoIncrement;comment:'文章ID'" json:"id"`
	CreatedAt time.Time `gorm:"autoCreateTime;type:datetime(0);comment:'创建时间'" json:"created_at"`
	UpdatedAt time.Time `gorm:"autoUpdateTime;type:datetime(0);comment:'更新时间'" json:"updated_at"`

	// 文章基本信息
	ArticleID int64  `gorm:"type:bigint(20);not null;unique;column:article_id;uniqueIndex:idx_article_id;comment:'文章唯一ID'" json:"article_id"`
	Title     string `gorm:"type:varchar(200);not null;column:title;index:idx_title;comment:'文章标题'" json:"title" binding:"required"`
	Content   string `gorm:"type:longtext;not null;column:content;comment:'文章内容'" json:"content" binding:"required"`
	Excerpt   string `gorm:"type:varchar(500);column:excerpt;comment:'文章摘要'" json:"excerpt"`

	// 状态相关字段
	Status int8 `gorm:"type:tinyint(4);default:0;column:status;comment:'文章状态:0草稿,1已发布,2已删除'" json:"status"`
	// PublishAt *time.Time `gorm:"column:publish_at;comment:'发布时间'" json:"publish_at"`

	// 外键关联 - 关联到用户表的UserID字段
	AuthorID   int64  `gorm:"type:bigint(20);not null;column:author_id;index:idx_author_id;comment:'作者ID'" json:"author_id"`
	Author     User   `gorm:"foreignKey:AuthorID;references:UserID;comment:'作者信息'" json:"-"`
	AuthorName string `gorm:"type:varchar(100);column:author_name;default:'';comment:'作者名称'" json:"author_name"`
	// 标签（可选，用于文章分类）
	Tags []Tags `gorm:"many2many:article_tag;foreignKey:ArticleID;joinForeignKey:ArticleID;References:TagID;joinReferences:TagID" json:"tags"`
}

func (a *Article) TableName() string {
	return "article"
}

type ReqArtical struct {
	Title   string `json:"title" binding:"required"`
	Content string `json:"content" binding:"required"`
	Excerpt string `json:"excerpt"`
	Tags    []Tags `json:"tags"`
}
